package com.dony.web.controller.store;

import java.util.Arrays;
import java.util.List;

import com.dony.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.dony.common.annotation.Log;
import com.dony.common.core.controller.BaseController;
import com.dony.common.core.domain.AjaxResult;
import com.dony.common.enums.BusinessType;
import com.dony.shop.domain.PriceConfig;
import com.dony.shop.service.IPriceConfigService;
import com.dony.common.core.page.TableDataInfo;

/**
 * 各站点价格配置Controller
 *
 * @author sundw
 * @date 2022-08-30
 */
@RestController
@RequestMapping("/store/priceConfig")
public class PriceConfigController extends BaseController {
    @Autowired
    private IPriceConfigService priceConfigService;

    /**
     * 查询各站点价格配置列表
     */
    @GetMapping("/list")
    public TableDataInfo list(PriceConfig priceConfig) {
        startPage();
        List<PriceConfig> list = priceConfigService.listByParam(priceConfig);
        return getDataTable(list);
    }


    /**
     * 获取各站点价格配置详细信息
     */
    @GetMapping(value = "/{configId}")
    public AjaxResult getInfo(@PathVariable("configId") Long configId) {
        return AjaxResult.success(priceConfigService.getById(configId));
    }

    /**
     * 新增各站点价格配置
     */
    @Log(title = "各站点价格配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PriceConfig priceConfig) {
        priceConfig.setTenantId(SecurityUtils.getDeptId());
        return toAjax(priceConfigService.save(priceConfig));
    }

    /**
     * 修改各站点价格配置
     */
    @Log(title = "各站点价格配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PriceConfig priceConfig) {
        return toAjax(priceConfigService.updateById(priceConfig));
    }

    /**
     * 删除各站点价格配置
     */
    @Log(title = "各站点价格配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{configIds}")
    public AjaxResult remove(@PathVariable Long[] configIds) {
        return toAjax(priceConfigService.removeBatchByIds(Arrays.asList(configIds)));
    }
}
